package 牛客网;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ali2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while ((str = br.readLine())!= null){
           // int mount = Integer.valueOf(str);
            //while (mount >0){
            //    mount--;
                String input = str;
                String[] in = input.split(" ");
                System.out.println(helper(in[0],Integer.valueOf(in[1])));;
           // }

        }
    }

    /**
     * 动态规划--先找出最大的回文字串
     * dp[][]表示ij之间的字符串是不是会问的
     * @param s
     * @param k
     */
    public static int helper(String s,int k){
        int mount  = 0;
        int len = s.length();
        boolean[][] dp = new boolean[len][len];

        String res = "";
        for (int l = 2;l<len;l++){
            for (int i = 0; i < len-1; i++) {
                int j = i+1;
                if (l == 0){
                    dp[i][j] = true;
                }else if (l == 1){
                    dp[i][j] = (s.charAt(i) == s.charAt(j));

                }else {
                    dp[i][j] = (s.charAt(i) == s.charAt(j)) && dp[i+1][j-1];
                }

                if (dp[i][j] && l>1){
                    mount++;
                }

            }
        }
        if (mount == k){
            return 0;
        }else {
            return Math.abs(k-mount);
        }


    }
}
